package com.howard.core;

import javax.sql.DataSource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;

/**
 *
 * new instance DataSource new instance JdbcTemplate new instance
 * SimpleJdbcTemplate new instance NamedParameterJdbcTemplate
 *
 * @author <a href="mailto:howard.he0329@gmail.com">Howard.He</a>
 *
 */
public abstract class AbstractBasicCoreDao {

	/** log */
	protected static Logger logger = LoggerFactory
			.getLogger(AbstractBasicCoreDao.class);

	@Autowired
	protected DataSource routingDataSource;

	protected JdbcTemplate jdbcTemplate;

	protected SimpleJdbcTemplate simpleJdbcTemplate;

	protected NamedParameterJdbcTemplate namedParameterJdbcTemplate;

	@Autowired
	public void init() {
		jdbcTemplate = new JdbcTemplate(routingDataSource);
		simpleJdbcTemplate = new SimpleJdbcTemplate(routingDataSource);
		namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(
				routingDataSource);
		jdbcTemplate.setFetchSize(1000);
		if (logger.isInfoEnabled()) {
			logger.info("jdbcTemplate: " + jdbcTemplate);
		}
	}

	public void setRoutingDataSource(final DataSource routingDataSource) {
		this.routingDataSource = routingDataSource;
	}

	public DataSource getRoutingDataSource() {
		return routingDataSource;
	}

	public JdbcTemplate getJdbcTemplate() {
		return jdbcTemplate;
	}

	public void setJdbcTemplate(final JdbcTemplate jdbcTemplate) {
		this.jdbcTemplate = jdbcTemplate;
	}

	public SimpleJdbcTemplate getSimpleJdbcTemplate() {
		return simpleJdbcTemplate;
	}

	public void setSimpleJdbcTemplate(
			final SimpleJdbcTemplate simpleJdbcTemplate) {
		this.simpleJdbcTemplate = simpleJdbcTemplate;
	}

	public NamedParameterJdbcTemplate getNamedParameterJdbcTemplate() {
		return namedParameterJdbcTemplate;
	}

	public void setNamedParameterJdbcTemplate(
			final NamedParameterJdbcTemplate namedParameterJdbcTemplate) {
		this.namedParameterJdbcTemplate = namedParameterJdbcTemplate;
	}
}
